<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    集合进阶(一)-(List)-(set) |  Yolin
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.png" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="Yolin" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-集合进阶-二-List-set" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  集合进阶(一)-(List)-(set)
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/07/28/%E9%9B%86%E5%90%88%E8%BF%9B%E9%98%B6-%E4%BA%8C-List-set/" class="article-date">
  <time datetime="2020-07-28T14:11:02.000Z" itemprop="datePublished">2020-07-28</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.7k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="一、数据结构"><a href="#一、数据结构" class="headerlink" title="一、数据结构"></a>一、数据结构</h2><p>数据结构是计算机存储、组织数据的方式。是指相互之间存在一种或多种特定关系的数据元素的集合。通常情况下，精心选择的数据结构可以带来更高的运行或存储效率。</p>
<h3 id="常见数据结构-栈"><a href="#常见数据结构-栈" class="headerlink" title="常见数据结构-栈"></a>常见数据结构-栈</h3><p>数据进入栈模型的过程称为：<strong>进栈</strong></p>
<p>数据离开栈模型的过程称为：<strong>出栈</strong></p>
<p>栈是一种<strong>先进后出</strong>的模型</p>
<ul>
<li>A-B-C-D进，D-C-B-A出</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_19-47-07.jpg?x-oss-process=image/resize,m_fill,h_180,w_290" alt=""></p>
<a id="more"></a>
<h3 id="常见数据结构-队列"><a href="#常见数据结构-队列" class="headerlink" title="常见数据结构-队列"></a>常见数据结构-队列</h3><p>数据从后端进入队列模型的过程称为：<strong>入队列</strong></p>
<p>数据从前端进入队列模型的过程称为：<strong>出队列</strong></p>
<p>队列是一种<strong>先进先出</strong>的模型</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_19-52-11.jpg?x-oss-process=image/resize,m_fill,h_360,w_290" alt=""></p>
<h3 id="常见数据结构-数组"><a href="#常见数据结构-数组" class="headerlink" title="常见数据结构-数组"></a>常见数据结构-数组</h3><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_19-55-03.jpg?x-oss-process=image/resize,m_fill,h_220,w_320" alt=""></p>
<ul>
<li><strong>查询效率高</strong>：查询数据通过索引定位，查询任意数据消耗时间相同</li>
<li><strong>删除效率低</strong>：删除数据时，要将原始数据删除，同时后面每个数据前移</li>
<li><strong>添加效率低</strong>：添加数据时，添加位置后的每个数据后移，再添加元素</li>
</ul>
<h3 id="常见数据结构-链表"><a href="#常见数据结构-链表" class="headerlink" title="常见数据结构-链表"></a>常见数据结构-链表</h3><hr>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_20-16-04.jpg" alt=""></p>
<hr>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_20-18-21.jpg" alt=""></p>
<hr>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_20-21-03.jpg" alt=""></p>
<h2 id="二、List集合子类的特点"><a href="#二、List集合子类的特点" class="headerlink" title="二、List集合子类的特点"></a>二、List集合子类的特点</h2><p>通过开发文档可以了解到</p>
<ul>
<li>ArrayList:底层数据结构是<strong>数组</strong>，查询快，增删慢</li>
<li>LinkList:底层数据结构是<strong>链表</strong>，查询慢，增删快。</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-26_22-06-37.jpg" alt=""></p>
<h2 id="三、LinkedList集合的特有功能"><a href="#三、LinkedList集合的特有功能" class="headerlink" title="三、LinkedList集合的特有功能"></a>三、LinkedList集合的特有功能</h2><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>public void addFirst(E e)</td>
<td>在该列表开头插入指定的元素</td>
</tr>
<tr>
<td>public void addLast</td>
<td>将指定的元素追加到此列表的末尾</td>
</tr>
<tr>
<td>public E getFirst()</td>
<td>返回此列表中的第一个元素</td>
</tr>
<tr>
<td>public E getLast()</td>
<td>返回此列表中的最后一个元素</td>
</tr>
<tr>
<td>public E removeFirst()</td>
<td>从此列表中删除并返回第一个元素</td>
</tr>
<tr>
<td>public E removeLast()</td>
<td>从此列表中删除并返回最后一个元素</td>
</tr>
</tbody></table>
<h2 id="四、Set集合"><a href="#四、Set集合" class="headerlink" title="四、Set集合"></a>四、Set集合</h2><h4 id="set集合特点"><a href="#set集合特点" class="headerlink" title="set集合特点"></a>set集合特点</h4><ul>
<li>不包含重复元素的集合</li>
<li>没有带索引的方法，所以不能使用普通for循环遍历</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SetDemo</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">        Set&lt;String&gt; set=<span class="keyword">new</span> HashSet&lt;String&gt;();</span><br><span class="line">        set.add(<span class="string">"hello"</span>);</span><br><span class="line">        set.add(<span class="string">"world"</span>);</span><br><span class="line">        set.add(<span class="string">"world"</span>);</span><br><span class="line">        <span class="keyword">for</span>(String s:set)&#123;</span><br><span class="line">            System.out.print(s);<span class="comment">//helloworld</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="五、哈希值"><a href="#五、哈希值" class="headerlink" title="五、哈希值"></a>五、哈希值</h2><p>哈希值是JDK根据对象的<strong>地址</strong>或<strong>字符串</strong>或<strong>数字</strong>算出来的int类型的数值</p>
<p>Object类中有一个方法可以<strong>获取对象的哈希值</strong></p>
<ul>
<li>public int hashCode():返回对象的哈希值</li>
</ul>
<h4 id="对象的哈希值特点"><a href="#对象的哈希值特点" class="headerlink" title="对象的哈希值特点"></a>对象的哈希值特点</h4><ul>
<li>同一个对象多次调用hashCode()方法返回的哈希值是相同的</li>
<li>默认情况下，不同对象的哈希值是不同的。而重写hashCode()方法可以实现让不同对象的哈希值相同</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_13-30-37.jpg" alt=""></p>
<h2 id="六、HashSet集合"><a href="#六、HashSet集合" class="headerlink" title="六、HashSet集合"></a>六、HashSet集合</h2><h4 id="HashSet集合特点"><a href="#HashSet集合特点" class="headerlink" title="HashSet集合特点"></a>HashSet集合特点</h4><ul>
<li>底层数据结构是哈希表</li>
<li>对集合的迭代顺序不坐任何保证，也就是说不保证存储和取出的元素顺序一致</li>
<li>没有带索引的方法，所以不能使用普通for循环遍历</li>
<li>由于是Set集合，所以是不包含重复元素的集合</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_13-40-39.jpg" alt=""></p>
<h4 id="HashSet集合保证元素唯一性分析"><a href="#HashSet集合保证元素唯一性分析" class="headerlink" title="HashSet集合保证元素唯一性分析"></a>HashSet集合保证元素唯一性分析</h4>
<div style="position:relative;width:100%;height:0;padding-bottom:75%;">
<iframe src="//player.bilibili.com/player.html?aid=62076359&bvid=BV1Kt411g7Sq&cid=107913372&page=93" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="position: absolute;width:100%;height: 100%;left: 0;top: 0;"> </iframe>
</div>


<h5 id="HashSet集合添加一个元素的过程："><a href="#HashSet集合添加一个元素的过程：" class="headerlink" title="HashSet集合添加一个元素的过程："></a>HashSet集合添加一个元素的过程：</h5><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_15-04-20.jpg" alt=""></p>
<ul>
<li><strong>要保证元素唯一性，需要重写hashCode()和equals()</strong></li>
</ul>
<h2 id="七、常见数据结构-哈希表"><a href="#七、常见数据结构-哈希表" class="headerlink" title="七、常见数据结构-哈希表"></a>七、常见数据结构-哈希表</h2><p>哈希表</p>
<ul>
<li>JDK8之前，底层采用<strong>数组+链表</strong>实现，可以说是一个元素为链表的数组</li>
<li>JDK8以后，在长度比较长的时候，底层实现了优化</li>
</ul>
<p>查看开发文档</p>
<ul>
<li>HashSet() </li>
<li>构造一个新的空集合; 背景HashMap实例具有默认初始容量（16）</li>
</ul>
<p>所以是一个长度为16的数组，要实现将哈希值存入数组需要进行计算：将哈希值对16取余数，根据余数放入指定位置</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_15-18-24.jpg" alt=""></p>
<h2 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h2><h4 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h4><p>创建一个存储学生对象的集合，存储多个学生对象，使用程序实现在控制台遍历该集合</p>
<h4 id="要求"><a href="#要求" class="headerlink" title="要求"></a>要求</h4><p>学生对象的成员变量值相同，我们就认为是同一个对象</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_15-31-32.jpg" alt=""></p>
<p>此时由于对象不同（哈希值也不同）导致重复。还需要<strong>重写hashCode()和equals()</strong></p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_15-35-46.jpg" alt=""></p>
<h2 id="八、LinkedHashSet集合概述和特点"><a href="#八、LinkedHashSet集合概述和特点" class="headerlink" title="八、LinkedHashSet集合概述和特点"></a>八、LinkedHashSet集合概述和特点</h2><h4 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h4><ul>
<li>哈希表和链表实现的Set接口，具有可预测的迭代次序</li>
<li>由链表保证元素有序，也就是说<strong>元素的存储和取出顺序是一致的</strong></li>
<li>由哈希表保证元素唯一，也就是说<strong>没有重复的元素</strong></li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_19-57-54.jpg" alt=""></p>
<h2 id="九、TreeSet集合"><a href="#九、TreeSet集合" class="headerlink" title="九、TreeSet集合"></a>九、TreeSet集合</h2><h4 id="TreeSet集合特点"><a href="#TreeSet集合特点" class="headerlink" title="TreeSet集合特点"></a>TreeSet集合特点</h4><ul>
<li>元素有序，这里的顺序不是指存储和取出的顺序，而是按照一定的规则进行排序，具体排序方式取决于构造方法</li>
</ul>
<table>
<thead>
<tr>
<th>构造方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>TreeSet()</td>
<td>根据其元素的自然排序进行排序</td>
</tr>
<tr>
<td>TreeSet(Comparator comparator)</td>
<td>根据指定的比较器进行排序</td>
</tr>
</tbody></table>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-27_20-36-49.jpg" alt=""></p>
<h4 id="自然排序Comparable的使用"><a href="#自然排序Comparable的使用" class="headerlink" title="自然排序Comparable的使用"></a>自然排序Comparable的使用</h4><ul>
<li>存储学生对象并遍历，创建TreeSet集合使用<strong>无参构造方法</strong></li>
<li>要求：按照年龄从小到大排序，年龄相同，按照姓名的字母顺序排序</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-28_12-58-11.jpg" alt=""></p>
<p>查看开发文档：</p>
<p>public interface Comparable<T></p>
<p>该接口对实现它的每个类的对象强加一个整体排序。 这个排序被称为类的自然排序 ，类的compareTo方法被称为其自然比较方法 。 </p>
<p>因而要实现排序的功能需要元素所属类先实现这个接口</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-28_14-14-53.jpg" alt=""></p>
<h4 id="比较器排序Comparator的使用"><a href="#比较器排序Comparator的使用" class="headerlink" title="比较器排序Comparator的使用"></a>比较器排序Comparator的使用</h4><ul>
<li>存储学生对象并遍历，创建TreeSet集合使用<strong>带参构造方法</strong></li>
<li>要求：按照年龄从小到大排序，年龄相同时，按照姓名的字母顺序排序</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-28_17-47-10.jpg" alt=""></p>
<p><strong>结论</strong></p>
<ul>
<li>用TreeSet集合存储自定义对象，带参构造方法使用的是<strong>比较器排序</strong>对元素进行排序的</li>
<li>比较器排序，就是<strong>让集合构造方法接收Comparator的实现类对象</strong>，重写compare(T o1,T o2)方法</li>
<li>重写方法时，一定要注意排序规则必须按照要求的主要和次要条件来写。</li>
</ul>
<h2 id="案例-1"><a href="#案例-1" class="headerlink" title="案例"></a>案例</h2><h4 id="①成绩排序"><a href="#①成绩排序" class="headerlink" title="①成绩排序"></a>①成绩排序</h4><p>需求：使用TreeSet集合存储多个学生信息(姓名，语文成绩，数学成绩),并遍历该集合</p>
<p>要求：按照总分从高到低出现<br><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-28_18-48-07.jpg" alt=""></p>
<p>ps：假设有同名同姓且成绩完全一样需要再用num3来判定</p>
<h4 id="②不重复的随机数"><a href="#②不重复的随机数" class="headerlink" title="②不重复的随机数"></a>②不重复的随机数</h4><p>需求：编写一个程序，获取10个1-20之间的随机数，要求随机数不能重复，并在控制台输出</p>
<p>思路:</p>
<ul>
<li>创建Set集合对象</li>
<li>创建随机数对象</li>
<li>判断集合的长度是不是小于10，（是）：产生一个随机数，添加到集合，循环该步骤</li>
<li>遍历集合</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-07-28_21-05-46.jpg" alt=""></p>
<p>如果使用TreeSet会给随机数排序</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Set&lt;Integer&gt; set=<span class="keyword">new</span> TreeSet&lt;Integer&gt;();</span><br></pre></td></tr></table></figure>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/List%E9%9B%86%E5%90%88/" rel="tag">List集合</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Set%E9%9B%86%E5%90%88/" rel="tag">Set集合</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag">数据结构</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/07/29/%E9%9B%86%E5%90%88%E8%BF%9B%E9%98%B6-%E4%B8%89-%E6%B3%9B%E5%9E%8B/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            集合进阶(三)-(泛型)
          
        </div>
      </a>
    
    
      <a href="/2020/07/26/Java-SE-%E9%9B%86%E5%90%88%E8%BF%9B%E9%98%B6-%E4%B8%80/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">集合进阶(一)-(Collection)-(List)</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        notify: false,
        verify: '',
        app_id: '',
        app_key: '',
        path: window.location.pathname,
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020-2021
        张金
      </li>
      <li>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
        <img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/beian.png">
        <a href="https://beian.miit.gov.cn"  style="color:#f72b07" target="_blank">陕ICP备20002449号</a>
      </li>

    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Yolin"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/playlist">歌单</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/video">视频</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友情链接</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['肠断月明红豆蔻,','月似当时,','人似当时否？'],
    startDelay: 1500,
    typeSpeed: 200,
    loop: true,
    backSpeed: 40,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: true
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>



<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>